# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     day141_pyqt5_qcolordialog
   Description :
   Author :       fuml
   date：          2019/9/21
-------------------------------------------------
   Change Activity:
                   2019/9/21:In this example, we determine the event sender
object.
-------------------------------------------------
"""
import  sys
from PyQt5.QtWidgets import (QWidget,QPushButton,QFrame,QColorDialog,QApplication)
from PyQt5.QtGui import QColor

class Example(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        color = QColor(0,0,0)

        self.btn = QPushButton('select color',self)
        self.btn.move(20,20)
        self.btn.clicked.connect(self.showDialog)

        self.frm = QFrame(self)
        self.frm.setStyleSheet('QWidget { background-color:%s }' % color.name())
        self.frm.setGeometry(20,50,150,150)

        self.setGeometry(300,300,250,200)
        self.setWindowTitle('Color dialog')
        self.show()

    def showDialog(self):
        col=QColorDialog.getColor()
        if col.isValid():
            self.frm.setStyleSheet('QWidget { background-color:%s }' % col.name())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())